package com.yudaob2b.elong.service;

import com.alibaba.fastjson.JSONObject;
import com.yudaob2b.business.entity.po.ElongHotelDetailPO;
import com.yudaob2b.business.entity.po.ElongHotelListTempPO;
import com.yudaob2b.business.service.ElongHotelDetailService;
import com.yudaob2b.elong.entity.vo.hoteldetail.SingleHotel;
import com.yudaob2b.elong.entity.vo.hotellist.HotelXMLIndex;
import com.yudaob2b.elong.enums.OperationTypeEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

/**
 * 酒店信息落地服务类
 *
 * @author Kidd.Tan
 * @email 298023780@qq.com
 * @date 7/5/1nu8 10:53 PM
 */
@Service("localHotelInfoService")
public class LocalHotelInfoService {

    @Resource(name = "elongHotelDetailService")
    private ElongHotelDetailService elongHotelDetailService;

    @Resource(name = "httpStaticService")
    private HttpStaticService httpStaticService;

    /**
     *
     * @param hotelId
     * @param operationTypeEnum
     */
    public void localHotelInfo(String hotelId, OperationTypeEnum operationTypeEnum) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            // 转换数据表实体对象
           /* ElongHotelListTempPO elongHotelListTempPO = new ElongHotelListTempPO();
            BeanUtils.copyProperties(hotelXMLIndex, elongHotelListTempPO);
            elongHotelListTempPO.setHotel_id(Integer.valueOf(hotelXMLIndex.getHotelId()));
            elongHotelListTempPO.setUpdated_time(sdf.parse(hotelXMLIndex.getUpdatedTime()));
            // save
            //elongHotelListTempService.insert(elongHotelListTempPO);


            SingleHotel singleHotel = httpStaticService.getHostDetail("cn", hotelXMLIndex.getHotelId());
            if (singleHotel != null) {
                ElongHotelDetailPO hotelDetailPO = new ElongHotelDetailPO();
                hotelDetailPO.setHotel_id(Integer.valueOf(singleHotel.getId()));
                hotelDetailPO.setDetail(JSONObject.toJSONString(singleHotel.getDetail()));
                hotelDetailPO.setRoom(JSONObject.toJSONString(singleHotel.getRooms()));
                hotelDetailPO.setImage(JSONObject.toJSONString(singleHotel.getImages()));
                hotelDetailPO.setReview(JSONObject.toJSONString(singleHotel.getReview()));
                try {
                    elongHotelDetailService.insert(hotelDetailPO);
                } catch (Exception e) {
                    System.out.println("Exception id : " + JSONObject.toJSONString(hotelXMLIndex.getHotelId()));
                    e.printStackTrace();
                }

            }*/

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
